<?php

/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.0
 *	LISENSE: FL87MPRYOA0R - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Auto Classifieds
 *	DOMAIN: www.siyaradiali.com
 *	FILE: UNSUBSCRIBE.INC.PHP
 *
 *	This script is a commercial software and any kind of using it must be 
 *	coordinate with Flynax Owners Team and be agree to Flynax License Agreement
 *
 *	This block may not be removed from this file or any other files with out 
 *	permission of Flynax respective owners.
 *
 *	Copyrights Flynax Classifieds Software | 2012
 *	http://www.flynax.com/
 *
 ******************************************************************************/

/* get requested e-mail address from post */
$hash = $rlValid -> xSql( $_GET['hash'] );
$type = $hash[0];

$email = substr($hash, 1, 32);
$date = substr($hash, 33);

switch ($type){
	case 1:
		$table = 'accounts';
		$field = 'Subscribe';
		$where = 'Mail';
		$value = 0;
		
		break;
	case 2:
		$table = 'subscribers';
		$field = 'Status';
		$where = 'Mail';
		$value = 'approval';
	
		break;
	case 3:
		$table = 'contacts';
		$where = 'Email';
		$field = 'Subscribe';
		$value = 0;
	
		break;
}

$id = $rlDb -> getOne('ID', "MD5(`{$where}`) = '{$email}' AND MD5(`Date`) = '{$date}' AND `{$field}` <> '{$value}'", $table);

if ( $id )
{
	/* update status */
	$reefless -> loadClass('Actions');
	
	$update = array(
		'fields' => array(
			$field => $value
		),
		'where' => array(
			'ID' => $id
		)
	);
	$rlActions -> updateOne($update, $table);
	
	$reefless -> loadClass( 'Notice' );
	$rlNotice -> saveNotice( str_replace('{sitename}', $GLOBALS['lang']['pages+title+home'], $lang['massmailer_newsletter_person_unsubscibed']) );
}
else
{
	$errors[] = str_replace('{sitename}', $GLOBALS['lang']['pages+title+home'], $lang['massmailer_newsletter_incorrect_request']);
	$rlSmarty -> assign_by_ref( 'errors', $errors );
}
